package com.devops.admin.util;

/**
 * @ClassName HttpCheckUtil
 * @Description TODO
 * @Author hepingguo
 * @Date 2022/4/19 15:58
 * @Version 1.0
 **/
public class HttpCheckUtil {

    public static boolean isURL(String str){
        boolean containHttp = str.contains("http") || str.contains("https");
        //转换为小写
        str = str.toLowerCase();
        //https、http、ftp、rtsp、mms
        String regex = "^((https|http|ftp|rtsp|mms)?://)"
                + "?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?" //ftp的user@
                + "(([0-9]{1,3}\\.){3}[0-9]{1,3}" // IP形式的URL- 例如：199.194.52.184
                + "|" // 允许IP和DOMAIN（域名）
                + "([0-9a-z_!~*'()-]+\\.)*" // 域名- www.
                + "([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\\." // 二级域名
                + "[a-z]{2,6})" // first level domain- .com or .museum
                + "(:[0-9]{1,5})?" // 端口号最大为65535,5位数
                + "((/?)|" // a slash isn't required if there is no file name
                + "(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$";
        return str.matches(regex) && containHttp;
    }

    public static void main(String[] args) {
        String url = "http://helm-wrap-lu-svc.cn:80";
        System.out.println(isURL(url));
    }
}
